package IO.file;

import java.io.File;
import java.io.IOException;

public class FileDemo {
    public static void main(String[] args) {
        File f = new File("demo.txt");
        if (!f.exists()) {
            try {
                f.createNewFile();
                System.out.println(f.getName() + " is a " + (f.isFile() ? "file" : "directory"));
                System.out.println("abs path = " + f.getAbsolutePath());
                System.out.println("URI = " + f.toURI());
                System.out.println("readable: " + f.canRead());
                System.out.println("writable: " + f.canWrite());
                System.out.println("executable: " + f.canExecute());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        File d = new File("test");
        d.mkdir();
        if (d.isDirectory()) {
            File c = new File(d, f.getName());
            f.renameTo(c);
            System.out.println(d.getName() + "is a directory, the files under it are: ");
            File[] files = d.listFiles();
            for (File file : files) {
                System.out.println(file.getName());
            }
            c.delete();
        }
        d.delete();
    }
}
